Use case: RNG generate NIST compliant random numbers in interrupt mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define LENGTH 8
RNG_HandleTypeDef hrng;
uint32_t aRandom32bit[LENGTH];
RNG_ConfigTypeDef p_config;
hrng.Instance = RNG;
hrng.Init.ClockErrorDetection = RNG_CED_ENABLE;
p_config.Config1 = 0x01;
p_config.Config2 = 0x00;
p_config.Config3 = 0x02;
p_config.ClockDivider = RNG_CLKDIV_BY_32;
p_config.NistCompliance = RNG_NIST_COMPLIANT;
P_config.AutoReset = RNG_ARDIS_ENABLE;
p_config.HealthTest = 0x00009AAE;
p_config.NoiseSource = 0x000358D1;
HAL_RNG_Init(&hrng);
HAL_RNGEx_SetConfig(&hrng, &p_config);
for (int cnt=0; cnt < LENGTH - 1; cnt++)
{
if (HAL_RNG_GenerateRandomNumber_IT(&hrng) == HAL_ERROR)
{
HAL_RNGEx_RecoverSeedError(&hrng);
}
}
|
#define LENGTH 8
hal_rng_handle_t hrng;
uint32_t aRandom32bit[LENGTH];
HAL_RNG_Init(&hrng, HAL_RNG);
HAL_RNG_SetCertifiedNISTConfig(&hrng);
HAL_RNG_EnableClockErrorDetection(&hrng);
if (HAL_RNG_GenerateRandomNumber_IT(&hrng,
aRandom32bit, LENGTH) == HAL_ERROR)
{
HAL_RNG_RecoverSeedError(&hrng);
}
|
Key changes ¶
HAL2 interrupt-based generation reports completion through HAL_RNG_GenerationCpltCallback.
In HAL2, random number generation APIs take a buffer and its size and fill it in one call.

